<?
/*
+--------------------------------------------------------------------------
|   TalkBack Ticket System
|   ========================================
|   by Oliver Hayman
|   (c) 2007 OlliesPage.net
|   ========================================
|   
|   
+---------------------------------------------------------------------------
|   > $Date: 2007-09-02 16:56:14 +0000 (Sun, 02 Sep 2007) $
|   > $Author: Oliver Hayman $
+---------------------------------------------------------------------------
|
|   > ViewTalkBack
|   > Main TalkBack Session viewing Module for users
|   > Date started: Saturday 01st September 2007 (17:05)
|
+--------------------------------------------------------------------------
*/
session_start(); if(!isset($_SESSION['username'])) { header("location: login.php"); } include('main.php'); 
if($_GET[reply] != true) { $load =''; } else { $load=' onLoad="document.forms[0].reply.focus()"'; } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><? if($_GET[reply] != true) {
echo '<meta http-equiv="Refresh" content="60;url=viewtalkback.php?id='.$_GET[id].'" />'; } ?>
<link REL="shortcut icon" HREF="favicon.ico" TYPE="image/x-icon">
<style>
.row2
{
	BACKGROUND-COLOR: #F7FAFF;
	COLOR: #000000;
    FONT-SIZE: 11px;
    FONT-FAMILY: Verdana, Arial, Helvetica;
}
.smalltext
{
    FONT-SIZE: 11px;
    COLOR: #333333;
    FONT-FAMILY: Verdana, Arial, Helvetica;
}
a.footer:link {		color: #333333; }
a.footer:visited {	color: #333333; }
a.footer:hover {	color: #333333; text-decoration: underline; }
a.footer:active {	color: #333333; }
a.footer {			text-decoration: none; }
.text
{
    FONT-SIZE: 13px;
    COLOR: #333333;
    FONT-FAMILY: Verdana, Arial, Helvetica;
}
</style>
</head>
<body<? echo $load; ?>>
<center><img src="images/header.jpg" /><br />
</center>
<?
if(isset($_POST['Uid']) && isset($_POST['reply'])) {
$name = $_SESSION[firstname].' '.$_SESSION[lastname];
if($_SESSION['anon'] != true) { $anon = 0; } else { $anon = 1; }
$Anon = 'SELECT `Anon` FROM `messages` WHERE `Uid`=\'11\'';
$anon = (mysql_fetch_row(mysql_query($Anon)));
$anon = $anon[0];
$sql = 'INSERT INTO `replys` (`Uid`, `RName`, `reply`, `replytime`, `anon`, `staff`) VALUES (\''.$_POST['Uid'].'\', \''.$name.'\', \''.htmlspecialchars($_POST['reply']).'\', CURRENT_TIMESTAMP, \''.$anon.'\', \'0\');';
if(!mysql_query($sql)) die(mysql_error());
$sql = 'UPDATE `messages` SET `status` = \'1\' WHERE `messages`.`Uid` = '.$_POST['Uid'].' LIMIT 1;';
if(!mysql_query($sql)) die(mysql_error());
} //-------------------------------------------------------
$id = $_GET['id'];
function Query1($id) {
$sql = 'SELECT * FROM messages WHERE Uid = \''.$id.'\' LIMIT 0, 1;';
$query = mysql_query($sql);
return $query; }
$query = Query1($id);
$num = mysql_num_rows($query);
$a = mysql_fetch_array($query);
//----[Session Check]-----
if($num < 1) {
die('TalkBack Session not found!<br /><a href="index.php">Return to TalkBack home</a>');
}
if($a[Uname] != $_SESSION['username']) { die('TalkBack Session not found!<br /><a href="index.php">Return to TalkBack home</a>'); }
//----[Session Check]-----
if($a[status] == 1) { $status = '<font color="#8BB467">On Hold</font>'; } elseif($a[status] == 2) { $status = '<font color="#FF0000">Requires Reply</font>'; } elseif($a[status] == 0) { $status = '<font color="#8A8A8A">Closed</font>'; } elseif($a[status] == 3) { $status = '<font color="#FF0000"><b>Reported</b></font>'; }
if($a[Respond] == 0) { $req = '<font color="#8A8A8A">No'; $lstRep = 'N/A'; $CounRep = 'N/A'; $activ = $a[time]; } else { $req = '<font color="#8A8A8A">Yes'; }
if($a[status] != 0) { $reply_link = '<a href="viewtalkback.php?id='.$a[Uid].'&reply=true"><img src="images/reply.jpg" alt="Reply" border="0"></a>'; } else { $reply_link = '<img src="images/closed.jpg" alt="Closed">'; }
if($a[Anon] != 0) { $name = 'Unreveiled'; } else { $name = $a[Name]; }
$replys = 'SELECT count(*) as total FROM replys WHERE `Uid`=\''.$a[Uid].'\';';
$replys = mysql_fetch_array(mysql_query($replys));
if($a[Respond] == 0 || ($replys < 1)) { $activ = $a['time']; } else { 
$activ = 'SELECT `replytime` FROM `replys` WHERE `Uid` = '.$a[Uid].' ORDER BY `replys` . `replytime` DESC LIMIT 0, 1;';
$activ = mysql_fetch_row(mysql_query($activ));
$activ = $activ[0]; }
$activ = date('d M Y, h:i A', strtotime($activ));
$opened = date('d M Y, h:i A', strtotime($a[time]));
$sql = 'SELECT `uid` FROM `users` WHERE `username`=\''.$a['Uname'].'\';'; $b = mysql_fetch_row(mysql_query($sql));
$sql = 'SELECT `type`, `activated` FROM `license codes` WHERE `reg_to`='.$b['0'].';'; $cID = $b[0]; unset($b);
$b = mysql_fetch_row(mysql_query($sql)); $b[activated] = date('d M Y, h:i A', strtotime($b['1']));
$sql = 'SELECT `name` FROM `types` WHERE `type`='.$b['0'].';'; $c = mysql_fetch_row(mysql_query($sql));
//------------------------------------------------------------------------------------------------------
if($_GET[reply] != true) {
print <<<EOA
<fieldset style="width: 80%; margin-bottom: 6px; color: #267DDC; BORDER: 1px SOLID #CCCCCC; -moz-border-radius: 4px 4px 4px 4px; padding: 4px">
	<legend>Session Details</legend>
	<table width="100%"  border="0" cellspacing="1" cellpadding="4">
	  <tr>
		<td width="15%" align="left" valign="top" class="row2"><span class="smalltext">Session ID: </span></td>
		<td align="left" valign="top" style="width: 21%"><span class="smalltext">$a[Uid]</span></td>

		<td align="left" valign="top" class="row2" style="width: 20%"><span class="smalltext">Client ID: </span></td>
		<td width="35%" align="left" valign="top"><span class="smalltext">$cID</span></td>
	  </tr>
	  <tr>
		<td width="15%" align="left" valign="top" class="row2"><span class="smalltext">Status: </span></td>
		<td align="left" valign="top" style="width: 21%"><span class="smalltext">$status</span></td>
		<td align="left" valign="top" class="row2" style="width: 20%"><span class="smalltext">Requires Responce: </span></td>

		<td width="35%" align="left" valign="top"><span class="smalltext">$req</font></span></td>
	  </tr>
	  <tr>
		<td width="15%" align="left" valign="top" class="row2"><span class="smalltext">License Type: </span></td>
		<td align="left" valign="top" style="width: 21%"><span class="smalltext">$c[0]</span></td>
		<td align="left" valign="top" class="row2" style="width: 20%"><span class="smalltext">License Activated: </span></td>
		<td width="35%" align="left" valign="top"><span class="smalltext">$b[activated]</span></td>
	  </tr>
	  <tr>
		<td width="15%" align="left" valign="top" class="row2"><span class="smalltext">Created On: </span></td>
		<td align="left" valign="top" style="width: 21%"><span class="smalltext">$opened</span></td>
		<td align="left" valign="top" class="row2" style="width: 20%"><span class="smalltext">Last Update: </span></td>
		<td width="35%" align="left" valign="top"><span class="smalltext">25 Aug 2007 06:52 PM</span></td>

	  </tr>
	  </table>
</fieldset>
<p align="right">$reply_link</p>
<table width="100%" border="1px" cellpadding="1" cellspacing="0" bordercolor="#0066FF">
  <tr>
    <th background="images/tablebg.gif" style="font-family: Verdana;">Conversation</th>
  </tr>
  <tr>
    <td border="0" style="padding: 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="1">
  <tr style="background-color: #87CEEB;">
    <th align="left" style="font-family: Verdana; font-size: 13px;">&nbsp;{$name}</th>
    <th align="right"><img src="images/student.jpg" alt="student" /> </th>
  </tr>
</table>
</td>
  </tr>
  <tr>
    <td border="0"><span class="text">&nbsp;Posted on $opened</span></font></td>
  </tr>
  <tr>
    <td border="0">
	<pre>{$a['Message']}</pre></td>
  </tr>
</table>
EOA;
$i = 0;
$sql = 'SELECT * FROM replys WHERE Uid = \''.$id.'\';';
$query = mysql_query($sql);
$R_num = mysql_num_rows($query);
while($i < $R_num) {
$b = mysql_fetch_array($query);
if($b['staff'] == 1) { $img = 'staff'; } else { $img = 'student'; }
$date = date('d M Y, h:i A', strtotime($b[replytime]));
if($b[anon] != 0) { $name = 'Unreveiled'; } else { $name = $b['RName']; }
if($img == 'staff') { $color = '#66FF66'; } else { $color = '#87CEEB'; }
print <<<EOA
<table width="100%" border="1px" cellpadding="1" cellspacing="0" bordercolor="#0066FF">
  <tr>
    <td border="0" style="padding: 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="1">
  <tr style="background-color: $color;">
    <th align="left" style="font-family: Verdana; font-size: 13px;">&nbsp;{$name}</th>
    <th align="right"><img src="images/$img.jpg" alt="$img" /> </th>
  </tr>
</table>
</td>
  </tr>
  <tr>
    <td border="0"><span class="text">&nbsp;Posted on $date</span></font></td>
  </tr>
  <tr>
    <td border="0">
	<pre>{$b['reply']}</pre></td>
  </tr>
</table>
EOA;
$i++;
}
echo '<br /><a href="index.php"><img src="images/back.jpg" border="0"></a>';
} else { //-------------------[TalkBack_Reply]--------------------------------------------
print <<<EOA
<form action="viewtalkback.php?id=$id" method="post">
<input type="hidden" name="Uid" value="$id">
<fieldset style="width: 50%; margin-bottom: 6px; color: #267DDC; BORDER: 1px SOLID #CCCCCC; -moz-border-radius: 4px 4px 4px 4px; padding: 4px">
	<legend>Details</legend>
	<table width="100%" border="0" cellspacing="1" cellpadding="4">
	  <tr>
		<td width="15%" align="left" valign="top" class="row2"><span class="smalltext">Name: </span></td>
		<td align="left" valign="top" style="width: 21%"><span class="smalltext">$name</span></td>
	  </tr>
	  <tr>
		<td width="15%" align="left" valign="top" class="row2"><span class="smalltext">Session ID: </span></td>
		<td align="left" valign="top" style="width: 21%"><span class="smalltext">$id</span></td>
	  </tr>
	  </table>
</fieldset>
<fieldset style="width: 50%; margin-bottom: 6px; color: #267DDC; BORDER: 1px SOLID #CCCCCC; -moz-border-radius: 4px 4px 4px 4px; padding: 4px">
	<legend>Your Reply</legend>
<textarea name="reply" rows="10" cols="30" style="width: 98%;"></textarea>
</fieldset>
<a href="#" onclick="javascript:document.forms[0].submit()"><img src="images/submit.jpg" alt="Submit" border="0" /></a>&nbsp;<a href="#" onclick="javascript:document.forms[0].reset()"><img src="images/reset.jpg" alt="Reset" border="0" /></a><br />
<br /><a href="viewtalkback.php?id=$a[Uid]"><img src="images/back.jpg" border="0"></a>
EOA;
}
footer();
?>
</body>
</html>